package com.shujia.day12;


import java.util.Objects;

public class Student implements Comparable<Student>{
    private String name;
    private int age;

    static String clazz = "bigdata26";

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public static void learn(){
        System.out.println("今天天气真好啊，是个学习的好时机...");
    }



    @Override
    public int compareTo(Student that) {
        // 传入的Student和当前Studen内部                                                                                                 t对象进行比较,其中this表示待插入的学生对象 that表示需要比较的学生对象

        // 比较逻辑： 先比较年龄 再比较其姓名
        int ageRes = this.age - that.age;

        return ageRes == 0 ? this.name.compareTo(that.name): ageRes;
    }
}
